﻿import gs.TweenLite;
import mx.utils.Delegate;
class cn.eminia.AS2.HandDoBtn {
	function HandDoBtn(btn, act, obj) {
		if (btn.constructor == Array) {
			for (var i = 0; i<btn.length; i++) {
				doOri(btn[i],act,obj);
			}
		} else {
			doOri(btn,act,obj);
		}
	}
	static function doOri(btn, act, obj) {
		/*btn.onEnterFrame = function() {
			this.gotoAndStop(1);
			delete this.onEnterFrame;
		};*/
		var scope=(obj.scope==null)?btn:obj.scope;
		if (btn.real != undefined) {
			//btn = btn.real;
			btn.hitArea= btn.real
		}
		btn.onRollOver = Delegate.create(btn, function () {
			this.onEnterFrame = function() {
				this.gotoAndStop(this._currentframe+1);
				if (this._currentframe == this._totalframes) {
					delete this.onEnterFrame;
				}
			};
		});
		btn.onRollOut = btn.onReleaseOutside=Delegate.create(btn, function () {
			this.onEnterFrame = function() {
				this.gotoAndStop(this._currentframe-1);
				if (this._currentframe == 1) {
					delete this.onEnterFrame;
				}
			};
		});
		btn.onRelease = (act == undefined) ? null : Delegate.create(scope, act);
		//附加属性
		if (obj != undefined) {
			for (var i in obj) {
				btn[i] = obj[i];
			}
		}
	}
	static function doStop() {
		for (var i = 0; i<arguments.length; i++) {
			var o = arguments[i];
			o.onEnterFrame = function() {
				delete this.onEnterFrame;
				this.gotoAndStop(1);
			};
		}
	}
	static function doNext() {
		for (var i = 0; i<arguments.length; i++) {
			var o = arguments[i];
			o.onEnterFrame = function() {
				if (this._currentframe == this._totalframes) {
					delete this.onEnterFrame;
				}
				this.gotoAndStop(this._currentframe+1);
			};
		}
	}
	//结束函数
	static function doEndFade() {
		for (var i = 0; i<arguments.length; i++) {
			var o = arguments[i];
			doEnd(o);
			TweenLite.to(o,1,{delay:0, _alpha:0});
		}
	}
	static function doEnd_go() {
	}
	//恢复函数
	static function doBackFade() {
		for (var i = 0; i<arguments.length; i++) {
			var o = arguments[i];
			doBack(o);
			TweenLite.to(o,1,{delay:0, _alpha:100});
		}
	}
	static function doEnd() {
		for (var i = 0; i<arguments.length; i++) {
			var o = arguments[i];
			o.onEnterFrame = function() { 
				delete this.onEnterFrame;
				this.gotoAndStop(this._totalframes);
			};
			//del(o)
			//o.pppp=(o.real!=undefined)?o:o._parent
			o.topDummy = o._parent.createEmptyMovieClip('dummy'+o._parent.getNextHighestDepth(), o._parent.getNextHighestDepth());
			//要调试， 把 fillAlpha:0 改成 fillAlpha:50
			var o_=(o.real!=undefined)?o.real:o;
			new cn.eminia.AS2.BLK(o.topDummy, {width:o_._width, height:o_._height, x:0, y:0, fillAlpha:50});
			 
			o.topDummy._x=(o.realOffsetX!=undefined)?o._x+o.realOffsetX:o._x;
			o.topDummy._y=(o.realOffsetY!=undefined)?o._y+o.realOffsetY:o._y; 
			o.topDummy.onRollOver = function() {
			};
			o.topDummy.useHandCursor = false;
			delete o.onRollOut;
		}
	}
	static function doBack() {
		for (var i = 0; i<arguments.length; i++) {
			var o = arguments[i];
			removeMovieClip(o.topDummy);
			o.onEnterFrame = function() {
				this.gotoAndStop(this._currentframe-1);
				//trace('this._currentframe'+this._currentframe);
				if (this._currentframe == 1) {
					delete this.onEnterFrame;
				}
			};
			o.onRollOut = function() {
				this.onEnterFrame = function() {
					this.gotoAndStop(this._currentframe-1);
					if (this._currentframe == 1) {
						delete this.onEnterFrame;
					}
				};
			};
		}
	}
	static function doPre(btn) {
		for (var i = 0; i<arguments.length; i++) {
			var o = arguments[i];
			o.onEnterFrame = function() {
				this.gotoAndStop(this._currentframe-1);
				//trace('this._currentframe'+this._currentframe);
				if (this._currentframe == 1) {
					delete this.onEnterFrame;
				}
			};
		}
	}
	static function record(btn) {
	}
	static function del(btn) {
		delete btn.onRollOut;
		delete btn.onRollOver;
		delete btn.onRelease;
		delete btn.onReleaseOutside;
		delete btn.onPress;
	}
	static function extrude(btn) {
		del(btn);
		btn.onEnterFrame = function() {
			this.gotoAndStop(this._currentframe+1);
			if (this._currentframe == this._totalframes) {
				delete this.onEnterFrame;
			}
		};
	}
}